<?php 
session_start();
require('../db/opendb.php');
require('common/functions.php');


//Add_Image($ListingID, "../listing_images/",$images, 0, $_SESSION["id"]);
$uploadpath = "../user_images/"; 
    $source = $HTTP_POST_FILES['image_file']['tmp_name']; 
    $dest = ''; 
	$filename='';
    if ( ($source != 'none') && ($source != '' )) { 

        $imagesize = getimagesize($source); 
		$imagetype = $imagesize[2];
        switch ( $imagesize[2] ) { 

            case 0: 

//                echo '<BR> Image is unknown <BR>'; 
                break; 

            case 1: 
//                echo '<BR> Image is a GIF <BR>'; 
                $dest = uniqid('img').'.gif'; 
                break; 
             
            case 2: 
//                echo '<BR> Image is a JPG <BR>'; 
                $dest = uniqid('img').'.jpg'; 
                break; 
             
            case 3: 
 //               echo '<BR> Image is a PNG <BR>'; 
                //$dest = uniqid('img').'.png'; 
                break; 
        } 

        if ( $dest != '' ) { 

            if ( move_uploaded_file( $source, $uploadpath.$dest ) ) { 
				chmod($uploadpath.$dest, 0644);
				//CreateThumbnail($source,$outputfile,$size)
				if($imagesize[0] > 100)
				{
				CreateThumbnailAgents($uploadpath.$dest,$uploadpath."t_".$dest,100);
				}
				else
				{
				CreateThumbnailAgents($uploadpath.$dest,$uploadpath."t_".$dest,$imagesize[0]);
				}
				//CreateResizeWidth($uploadpath.$dest,$uploadpath."resize_".$dest,400);
				$query = "update Users set Company_Logo = '".$dest."' where ID = '".$_SESSION['id']."'";
				//echo $query;
				mysql_query($query) or die(mysql_error()); 

            } else { 
				$message='The image file could not be stored,<BR> Please go back and try again.'; 
				
            } 

        }  

   		 } 
		 else 
		 { 

	        $message='There is a problem with the image file, <br> it could not be stored,<BR> Please go back and try again.'; 
			
    	}
echo "<meta http-equiv=refresh content=0;URL=edit_user.php>";

?>